import HTMLParser
import urllib
import re


urlString = "http://www.espanix.net/esp/lstsocios.asp"
urlText = []
pathOut = "ixp_members.txt"


class Parse39 (HTMLParser.HTMLParser):
    
    check = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "font":
            for name, value in attrs:
                if name == "class" and value == "fuente12V":
                    self.check = True
    
    def handle_data (self, data):
        if self.check == True and re.match("^\[ *AS *\d+ *\]$",data):
            # estraggo solo i caratteri numerici
            data = re.sub("\D","",data)
            if data not in urlText:
                urlText.append(data)
        self.check = False


lparser = Parse39()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "39 %s" % item
fileOut.close()